 // 提交表单数据
$(function(){
    $('#btn').click(function(){
        var menu_id = $('#menu_id').val();
        var rank = $('#rank').val().replace(/(^\s*)|(\s*$)/g, "");
        console.log(rank);
        var name = $('#name').val();
        var brand = $('#brand').val();
        var model = $('#model').val().replace(/(^\s*)|(\s*$)/g, "");
        var color = $('#color').val().replace(/(^\s*)|(\s*$)/g, "");
        var price = $('#price').val().replace(/(^\s*)|(\s*$)/g, "");
        var sort = $('#sort').val();
        if(brand == ''){layer.msg('请输入品牌');return;}
        var ccc = layer.load(2);
        $.ajax({
            url: "edit_menu",
            type: "POST",
            data: {
                'menu_id': menu_id,
                'rank': rank,
                'brand': brand,
                'model': model,
                'color': color,
                'price': price,
                'sort':sort
            },
            dataType: "json",
            success: function(re){
                layer.close(ccc);
                if(re.errcode == 0){
                    layer.msg(re.errmsg,{icon:1,time:1000},function(){
                        location.href = history.go(-1);
                    });
                }else{
                    layer.msg(re.errmsg,{icon:2});
                }
            },
            error: function(){
                layer.close(ccc);
                layer.msg('请检查网络',{icon:2});
            },
            timeout: 10000
        });
    });
});
 $(function(){
     ajax_get_table('search_form',1);
 });
 //Ajax抓取页面
 function ajax_get_table(form,page){
     // 当前页面,保存为全局变量
     present_page = page;
     $.ajax({
         type: "POST",
         cache: false,
         url: "ajax_index?p="+page,
         data: $('#'+form).serialize(),
         dataType: "html",
         success: function(data){
             $("#ajax_return").html('');
             $("#ajax_return").append(data);
         }
     });
     return false;
 }
 //删除分类
 function delete_this(i){
     if(!i){layer.msg("非法操作");return;}
     layer.confirm('确定删除该分类吗？',{title:'提示'},function(index){
         layer.close(index);
         var ccc = layer.load(2);
         $.ajax({
             url: "delete_menu",
             type: "POST",
             data: {"menu_id": i},
             dataType: "json",
             success: function(re){
                 layer.close(ccc);
                 if(re.errcode == 0){
                     layer.msg(re.errmsg,{icon:1,time:1000},function(){
                         ajax_get_table('search_form',present_page);
                     });
                 }else{
                     layer.msg(re.errmsg,{icon:2});
                 }
             },
             error: function(){
                 layer.close(ccc);
                 layer.msg("请检查网络",{icon:2});
             },
             timeout: 10000
         });
     });
 }